package com.example.stray_animal_management_system.util;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * @description:
 * @author: panpan
 * @time: 2025/11/8
 */
public class SystemInfo {

    public static void main(String[] args) {
        getSystemInfo();
    }

    public static void getSystemInfo() {
        // 获取操作系统信息
        OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        System.out.println("Operating System: " + osBean.getName());
        System.out.println("OS Version: " + osBean.getVersion());
        System.out.println("Available processors (cores): " + osBean.getAvailableProcessors());
        System.out.println("System load average: " + osBean.getSystemLoadAverage());

        // 获取内存信息
        long totalMemory = Runtime.getRuntime().totalMemory();
        long freeMemory = Runtime.getRuntime().freeMemory();
        System.out.println("Total memory: " + totalMemory / (1024 * 1024) + " MB");
        System.out.println("Free memory: " + freeMemory / (1024 * 1024) + " MB");

        // 获取磁盘信息
        File[] roots = File.listRoots();
        for (File root : roots) {
            System.out.println("Drive: " + root);
            System.out.println("Total space: " + root.getTotalSpace() / (1024 * 1024 * 1024) + " GB");
            System.out.println("Free space: " + root.getFreeSpace() / (1024 * 1024 * 1024) + " GB");
        }

        // 获取网络信息
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface networkInterface = networkInterfaces.nextElement();
                Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress inetAddress = inetAddresses.nextElement();
                    System.out.println("Network Interface: " + networkInterface.getName());
                    System.out.println("IP Address: " + inetAddress.getHostAddress());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}